<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;
use Illuminate\Contracts\Validation\Validator;

class GoodsPublishRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'class_id'            => 'required|numeric|exists:goods_categories,id', // 全局分类 ID
            'category_id'         => 'required|numeric|exists:goods_categories,id', // 分类 ID
            'grant_status'        => 'boolean', // 授权状态
            'name'                => 'required', // 商品名称
            'brand_id'            => 'required|numeric|exists:brands,id', // 品牌 ID
            'original_price'      => 'required|numeric|min:0', // 原始价格
            'province_id'         => 'required|exists:areas,id,level,1', // 省份 ID
            'city_id'             => 'required|exists:areas,id,level,2', // 城市 ID
            'county_id'           => 'required|exists:areas,id,level,3', // 乡镇 ID
            'stock'               => 'required|integer|min:0', // 库存
            'minimum_order'       => 'required|integer|min:0', // 最小起订量
            'cn'                  => 'required', // 货号
            'unit'                => 'required|string', // 重量
            'display'             => 'required|integer', // 展示状态、权限
            'sell_status'         => 'boolean', // 是否上架
            'recommend_status'    => 'boolean', // 是否推荐
            'detail'              => 'required', // 商品详情
            'spec_first_name'     => 'string', // 规格字段名 1
            'spec_second_name'    => 'string', // 规格字段名 2
            'spec_third_name'     => 'string', // 规格字段名 3
            'spec_forth_name'     => 'string', // 规格字段名 4
            'spec_fifth_name'     => 'string', // 规格字段名 5

            // 规格部分
            'spec_first'          => 'required_with:spec_first_name|array',
            'spec_second'         => 'required_with:spec_second_name|array',
            'spec_third'          => 'required_with:spec_third_name|array',
            'spec_forth'          => 'required_with:spec_forth_name|array',
            'spec_fifth'          => 'required_with:spec_fifth_name|array',
            'spec_original_price' => 'required_with:spec_first_name,spec_second_name,spec_third_name,spec_forth_name,spec_fifth_name|array',
            'spec_stock'          => 'required_with:spec_first_name,spec_second_name,spec_third_name,spec_forth_name,spec_fifth_name|array',
            'spec_cn'             => 'required_with:spec_first_name,spec_second_name,spec_third_name,spec_forth_name,spec_fifth_name|array',
        ];
    }

    public function messages()
    {
        return [
            'class_id.required'       => '您未选取全局分类',
            'category_id.required'    => '您未选取店铺分类',
            'province_id.required'    => '您未选择省份',
            'city_id.required'        => '您未选择城市',
            'county_id.required'      => '您未选择乡镇/区县/街道',
            'original_price.required' => '请填写商品价格',
            'brand_id.required'       => '您未选择商品所属的品牌',
        ];
    }

}
